//
//  DBJTools.m
//  DBJ
//
//  Created by 花化华 on 2016/11/16.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "DMTools.h"

@implementation DMTools

#pragma mark - 键盘伸缩
+ (void)keybordWillChange:(NSNotification *)noteInfo andView:(UIView *)view{
    
    //1.获取键盘Y值
    CGRect rectEnd = [noteInfo.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyBoardY = rectEnd.origin.y;
    
    //2.计算平移的值
    CGFloat height = view.frame.size.height+64;
    CGFloat tranformValue = keyBoardY - height;
    
    //3.view平移
    [UIView animateWithDuration:0.25 animations:^{
        view.transform = CGAffineTransformMakeTranslation(0, tranformValue);
    }];
    
}

#pragma mark - 弹框
+ (void)dmShowSVProgress:(NSString *)content andTime:(float)delay{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:DMRGBCOLOR];
    [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"%@",content]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}

+ (void)dmShowSVTitle:(NSString *)content andTime:(float)delay{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeGradient];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:DMRGBCOLOR];
    [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"%@",content]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}

+ (void)dmShowSVErrorTitle:(NSString *)content andTime:(float)delay{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:DMRGBCOLOR];
    [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",content]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}

+ (void)dmShowSVSuccessTitle:(NSString *)content andTime:(float)delay{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:DMRGBCOLOR];
    [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"%@",content]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}

//#pragma mark - 更新／设置当前用户模型
//+ (void)updateCurrentIDModel:(DBJLoginModel *)loginModel{
//
//    //获取当前用户id
//    NSString *name = [DBJUserDefaultsTool objetForKey:CURRENTID];
//    
//    if (loginModel && name) {
//        
//        //将loginModel类型变为NSData类型
//        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:loginModel];
//        
//        //更新本地数据
//        [DBJUserDefaultsTool saveObject:data forKey:[NSString stringWithFormat:@"%@-MODEL",name]];
//    }
//
//}
//
//+ (DBJLoginModel *)getCurrentIDModel;{
//    
//    //获取当前用户id
//    NSString *name = [DBJUserDefaultsTool objetForKey:CURRENTID];
//    //创建DBJLoginModel
//    DBJLoginModel *model = nil;
//    //判断name是否nil
//    if (name) {
//        NSData *modelData = [DBJUserDefaultsTool objetForKey:[NSString stringWithFormat:@"%@-MODEL",name]];
//        model = [NSKeyedUnarchiver unarchiveObjectWithData:modelData];
//        NSLog(@"DBJLoginModel: %@",model);
//    }
//    
//    return model;
//}

@end
